import { Component, OnInit, EventEmitter, Output } from '@angular/core';
import { MapLegendService } from '../map-legend.service';
import { Subscription } from 'rxjs';

@Component({
  selector: 'kylin-map-legend',
  templateUrl: './map-legend.component.html',
  styleUrls: ['./map-legend.component.less']
})
export class MapLegendComponent implements OnInit {
  selectedValue = null;
  mapLegend = null;
  @Output() close: EventEmitter<boolean> = new EventEmitter<boolean>();
  subscription: Subscription;
  // rxjs 订阅模式
  constructor(public mapLegendService: MapLegendService) {
    this.subscription = this.mapLegendService.changeObservable.subscribe(
      (layerId) => {
        console.log(layerId);
        if (this.selectedValue === layerId) {
          this.selectedValue = null;
          this.mapLegend = [];
        }
      }
    );
  }

  ngOnInit() {
  }

  clickClose() {
    this.close.emit(false);
  }
  selectChange($event) {
    this.mapLegend = this.mapLegendService.fetchMapLegendData($event);
  }

}
